home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / clp_brws.arc / BROWSE.PRG < prev    next >
Text File  |  1986-07-04  |  17KB  |  605 lines

  1. **    Last revision: July 4, 1986 at 10:42
  2.  
  3. * Name:    BROWSE.prg    a dBASEIII Browse emulation for Clipper
  4. * Use :    RUN BROWSE <filename>
  5. *          DO Browse WITH <filename>
  6.  
  7. * 07/04/86 by: H.M. Van Tassell
  8. * This browse was inspired by a browse procedure written by S.J. Straley.
  9. * It ia a completely rewritten version of the his original procedure.
  10.  
  11. * This program is freely placed in the Public Domain with no
  12. * rights reserved. It is a non-copyrighted work!
  13.  
  14. * NOTE: uses CALLs to Curson & CursOff which are contained in the
  15. * author's CLIP-BRO.ARC CURSOR.OBJ ready for linking to this program.
  16.  
  17. ********[ If using browse as a procedure in another pgm ]***********
  18. **                                                                **
  19. ** If database file is already open, comment out "DO B_OpnFil"    **
  20. **   which is about 37 lines forward.                             **
  21. **                                                                **
  22. ** Suggest that SET ScoreBoard=Off, Confirm=On, Deleted = Off     **
  23. **   this should be done prior to calling Browse                  **
  24. **                                                                **
  25. ********************************************************************
  26.  
  27.   SET SCOREBOARD OFF 
  28.   SET CONFIRM ON     
  29.  
  30. **  PROCEDURE Browse                                               
  31. PARAMETER file
  32. PRIVATE temp, last_fld, curr_rec, curr_top, col_pos, row_pos, cur_field   
  33. PRIVATE last_posit, frst_posit, cur_posit, in_val, in_command, last_row
  34. PRIVATE curr_bot, Field_Length
  35. *                                                                             *
  36. *    last_fld    :   provides the number of fields available in given file.   *
  37. *    curr_rec    :   curr_rec record number of database highlited                       *
  38. *    curr_top    :   record number currently first on screen
  39. *    curr_bot    :   record number currently last on screen
  40. *    col_pos     :   column position of cursor on screen                      *
  41. *    row_pos     :   row position of cursor on screen                          *
  42. *    last_row    :   row count of current last row
  43. *    cur_field   :   the field number currently BROWSE is resting on in       *
  44. *                    CURRENT record of used FILE.                             *
  45. *    last_posit  :   the field number allowed to be shown in the last         *
  46. *                    column position                                          *
  47. *    frst_posit  :   the field number allowed to be shown in the first        *
  48. *                    column position                                          *
  49. *    in_val      :   the name of the field at any given cur_field              *
  50. *    in_command  :   the variable to store the INKEY()                        *
  51. *    Field_Length[]  an array of field lengths
  52. *
  53. file = UPPER(TRIM(file))
  54. IF AT(".",file) = 0
  55.    file = file + ".DBF"
  56. ENDIF
  57. **  If database file is already open, comment out "DO B_OpnFil"
  58.   DO B_OpnFil
  59. **
  60. CALL CursOff
  61. DO B_DrMenu
  62. @ 0,62 SAY TRIM(file)
  63.  
  64. curr_rec   = RECNO()
  65. curr_top   = curr_rec 
  66.  
  67. * for speed, setup an array of field lengths
  68. last_fld = B_FLDCNT()
  69. DECLARE Field_Length[last_fld]
  70. FOR cur_posit = 1 TO last_fld
  71.   Field_Length[cur_posit] = B_FLDLEN(cur_posit)
  72. NEXT
  73. col_pos    = 1
  74. cur_field  = 1
  75. row_pos    = 9
  76. frst_posit = 1
  77. last_posit = 0
  78.  
  79. last_posit = B_R_PAN()
  80. DO B_RecNum
  81. DO B_DrHead
  82. GoTo curr_rec
  83. DO B_ReDraw
  84. GoTo curr_rec
  85. DO B_ShoRev
  86.  
  87. DO WHILE .T.
  88.    DO B_ClrKey
  89.    in_command = UPPER(CHR(INKEY(0)))
  90.    DO B_ClrKey
  91.  
  92.    DO CASE
  93.    CASE in_command = CHR(27)  && ESC quit/exit
  94.       CLEAR
  95.       CALL CursOn
  96.       RETURN
  97.  
  98.    CASE in_command = "G"   && GoTo record
  99.      temp = curr_rec
  100.      @ 23,18 SAY "GoTo which record ?"
  101.      @ 24,27 SAY "Range 1 to "
  102.      @ 24,38 SAY RECCOUNT() PICTURE "@B"
  103.      CALL CursOn
  104.      @ 23,38 GET temp PICTURE "9999999" 
  105.      READ
  106.      DO WHILE temp <1 .OR. temp > RECCOUNT()
  107.        @ 23,38 GET temp PICTURE "9999999"
  108.        READ
  109.      ENDDO
  110.      CLEAR GETS
  111.      CALL CursOff
  112.      @ 23,0
  113.      @ 24,0
  114.      IF temp <> curr_rec
  115.        curr_rec = temp
  116.        curr_top = curr_rec
  117.        GoTo curr_rec
  118.        DO B_RecNum
  119.        DO B_ReDraw
  120.        row_pos = 9
  121.        GoTo curr_rec
  122.        DO B_ShoRev
  123.      ENDIF
  124.  
  125.    CASE in_command = CHR(25)   && ^Y  delete field
  126.       in_val = FIELDNAME(cur_field)
  127.       DO CASE
  128.       CASE TYPE(in_val) = "C"
  129.          REPLACE &in_val WITH SPACE(Field_Length[cur_field])
  130.       CASE TYPE(in_val) = "N"
  131.          REPLACE &in_val WITH 0.00
  132.       CASE TYPE(in_val) = "D"
  133.          REPLACE &in_val WITH CTOD("  /  /  ")
  134.       CASE TYPE(in_val) = "L"
  135.          REPLACE &in_val WITH .F.
  136.       ENDCASE
  137.       DO B_ShoRev
  138.  
  139.    CASE in_command = "E"
  140.       IF TYPE(in_val) <> "M"
  141.         @ row_pos, col_pos GET &in_val
  142.         CALL CursOn
  143.         READ
  144.         CALL CursOff
  145.         tempin = FIELDNAME(cur_field)
  146.         REPLACE &tempin WITH &in_val
  147.         CLEAR GETS
  148.       ENDIF
  149.  
  150.    CASE in_command = CHR(21)  && ^U  delete record
  151.       IF DELETED()
  152.          RECALL
  153.          @ row_pos,0 SAY " "
  154.          @ 00,50 SAY "     "
  155.       ELSE
  156.          DELETE
  157.          @ row_pos,0 SAY "*"
  158.          @ 00,50 SAY "*DEL*"
  159.       ENDIF
  160.  
  161.    CASE in_command = CHR(4)  && RtArrow
  162.       IF cur_field < last_fld
  163.          IF cur_field < last_posit
  164.             DO B_SayRt
  165.             cur_field = cur_field + 1
  166.             DO B_ShoRev
  167.          ELSE
  168.             * pan right
  169.             IF Field_Length[last_posit]+Field_Length[last_posit+1] > 80
  170.               frst_posit = last_posit + 1
  171.             ELSE
  172.               frst_posit = last_posit
  173.             ENDIF
  174.             cur_field = frst_posit
  175.             last_posit = B_R_PAN()
  176.             DO B_DrHead
  177.             GoTo curr_top
  178.             DO B_ReDraw
  179.             GoTo curr_rec
  180.             col_pos = 1
  181.             DO B_ShoRev
  182.          ENDIF
  183.       ENDIF
  184.  
  185.    CASE in_command = CHR(19) && LtArrow
  186.       IF cur_field  > 1
  187.          IF cur_field > frst_posit
  188.             cur_field = cur_field - 1
  189.             DO B_SayLt
  190.             DO B_ShoRev
  191.           ELSE 
  192.             ** cur_field is equal to frst_posit so pan left
  193.             IF Field_Length[frst_posit]+Field_Length[frst_posit-1] > 80
  194.               last_posit = frst_posit - 1
  195.             ELSE
  196.               last_posit = frst_posit
  197.             ENDIF
  198.             cur_field = last_posit   
  199.             frst_posit = B_L_PAN()  
  200.             cur_field = frst_posit
  201.             IF cur_field = 1
  202.               * make sure max fields displayed on screen
  203.               last_posit = B_R_PAN()
  204.             ENDIF
  205.             DO B_DrHead
  206.             GoTo curr_top
  207.             DO B_ReDraw
  208.             GoTo curr_rec
  209.             col_pos = 1
  210.             DO B_ShoRev
  211.          ENDIF
  212.       ENDIF
  213.  
  214.    CASE in_command = CHR(2)  && ^RtArrow pan right
  215.       IF last_posit < last_fld
  216.          IF Field_Length[last_posit]+Field_Length[last_posit+1] > 80
  217.            frst_posit = last_posit + 1
  218.          ELSE
  219.            frst_posit = last_posit
  220.          ENDIF
  221.         cur_field = frst_posit
  222.         last_posit = B_R_PAN()
  223.         DO B_DrHead
  224.         GoTo curr_top
  225.         DO B_ReDraw
  226.         GoTo curr_rec
  227.         col_pos = 1
  228.         DO B_ShoRev
  229.       ENDIF
  230.  
  231.    CASE in_command = CHR(26) && ^LtArrow  pan left
  232.       IF frst_posit  > 1
  233.         IF Field_Length[frst_posit]+Field_Length[frst_posit-1] > 80
  234.           last_posit = frst_posit - 1
  235.         ELSE
  236.           last_posit = frst_posit
  237.         ENDIF
  238.         cur_field = last_posit   
  239.         frst_posit = B_L_PAN()  
  240.         cur_field = frst_posit
  241.          IF cur_field = 1
  242.            * make sure max fields displayed on screen
  243.            last_posit = B_R_PAN()
  244.         ENDIF
  245.         DO B_DrHead
  246.         GoTo curr_top
  247.         DO B_ReDraw
  248.         GoTo curr_rec
  249.         col_pos = 1
  250.         DO B_ShoRev
  251.       ENDIF
  252.  
  253.    CASE in_command = CHR(18) && PgUp   
  254.       GoTo curr_top
  255.       SKIP - 12
  256.       curr_rec = RECNO()
  257.       curr_top=curr_rec
  258.       DO B_RecNum
  259.       DO B_ReDraw
  260.       row_pos = 9
  261.       GoTo curr_rec
  262.       DO B_ShoRev
  263.  
  264.    CASE in_command = CHR(3)  && PgDn   
  265.       GoTo curr_bot
  266.       SKIP + 1
  267.       IF EOF()
  268.         SKIP - 1
  269.       ENDIF
  270.       curr_rec = RECNO()
  271.       curr_top = curr_rec
  272.       DO B_RecNum
  273.       DO B_ReDraw
  274.       row_pos = 9
  275.       GoTo curr_rec
  276.       DO B_ShoRev
  277.  
  278.  
  279.    CASE in_command =  CHR(31)  && ^PgUp go to top of file
  280.       GoTo TOP
  281.       curr_rec = RECNO()
  282.       curr_top=curr_rec
  283.       DO B_RecNum
  284.       DO B_ReDraw
  285.       row_pos = 9
  286.       GoTo curr_rec
  287.       DO B_ShoRev
  288.  
  289.    CASE in_command = CHR(30)  && ^PgDn go to bottom of file
  290.       GoTo BOTTOM
  291.       curr_rec = RECNO()
  292.       curr_top = curr_rec
  293.       DO B_RecNum
  294.       DO B_ReDraw
  295.       row_pos = 9
  296.       GoTo curr_rec
  297.       DO B_ShoRev
  298.  
  299.    CASE in_command = CHR(24) && DnArrow
  300.       SKIP
  301.       IF EOF()
  302.          SKIP - 1
  303.       ELSE
  304.          SKIP - 1
  305.          row_pos = row_pos + 1
  306.          DO B_DnRec
  307.          SKIP + 1
  308.          curr_rec = RECNO()
  309.          DO B_RecNum
  310.          DO B_ShoRev
  311.       ENDIF
  312.  
  313.    CASE in_command = CHR(5)  && UpArrow
  314.       SKIP - 1
  315.       IF BOF()
  316.          GoTo curr_rec
  317.       ELSE
  318.          SKIP + 1
  319.          row_pos = row_pos - 1
  320.          DO B_UpRec
  321.          SKIP - 1
  322.          curr_rec = RECNO()
  323.          DO B_RecNum
  324.          DO B_ShoRev
  325.       ENDIF
  326.  
  327.    CASE in_command = CHR(1) && HOME move to first  screen row
  328.       IF TYPE(in_val) = "M"
  329.          @ row_pos,col_pos SAY "memo"
  330.       ELSE
  331.          @ row_pos,col_pos SAY &in_val
  332.       ENDIF
  333.       row_pos = 9
  334.       GoTo curr_top 
  335.       curr_rec = RECNO()
  336.       DO B_RecNum
  337.       DO B_ShoRev
  338.  
  339.    CASE in_command = CHR(6) && END  move to bottom screen row
  340.       IF TYPE(in_val) = "M"
  341.          @ row_pos,col_pos SAY "memo"
  342.       ELSE
  343.          @ row_pos,col_pos SAY &in_val
  344.       ENDIF
  345.       GoTo curr_bot
  346.       curr_rec = RECNO()
  347.       row_pos = last_row
  348.       DO B_RecNum
  349.       DO B_ShoRev
  350.  
  351.    OTHERWISE
  352.    ENDCASE
  353.  
  354. **  Debuging stuff
  355. **     @ 23,1  SAY "Frst_posit =" + STR( frst_posit,3)
  356. **     @ 23,20 SAY "Last_posit =" + STR( last_posit,3)
  357. **     @ 23,40 SAY "cur_field =" + STR( cur_field,3) 
  358. **     @ 23,60  SAY "last_fld = " + STR( last_fld,3) 
  359. **
  360. **     @ 24,1  SAY "Row_pos =" + STR( row_pos,3) 
  361. **     @ 24,20  SAY "curr_top =" + STR( curr_top,3) 
  362. **     @ 24,40 SAY "Col_pos =" + STR( col_pos,3) 
  363. **     @ 24,60 SAY "in_val = " + in_val + SPACE(10-LEN(in_val))
  364.  
  365. ENDDO
  366.  
  367. ********* begin procedures and functions ******************
  368.  
  369. PROCEDURE B_OpnFil
  370.  
  371.   IF file = "."
  372.      file = SPACE(14)
  373.      @ ROW(),0 SAY "No database is in USE.  Enter file name: " GET file PICTURE "!!!!!!!!!!!!!!"
  374.      READ
  375.      file = TRIM(file)
  376.      IF AT(".",file) = 0
  377.         file = file + ".DBF"
  378.      ENDIF
  379.   ENDIF
  380.   IF .NOT. FILE("&file")
  381.      ? file + " not found"
  382.      WAIT
  383.      QUIT
  384.   ENDIF
  385.   USE &file
  386.   RETURN
  387.  
  388. PROCEDURE B_ClrKey
  389.    * clear out the key board buffer
  390.    PRIVATE temp
  391.    temp = 1
  392.    DO WHILE temp <> 0
  393.      temp = INKEY()
  394.    ENDDO
  395.    RETURN
  396.  
  397. PROCEDURE B_DrMenu
  398. CLEAR
  399. @ 0,1 SAY "Record No.                   BROWSE                                             "
  400. @ 1,0 SAY "╔══════════════════╦════════════════════╦══════════════════╦═══════════════════╗"
  401. @ 2,0 SAY "║ CURSOR   Lt  Rt  ║        UP   DOWN   ║      DELETE      ║      ACTION       ║"
  402. @ 3,0 SAY "║  Char:   -  -  ║ Rec:             ║ Char:     DEL    ║ GoTo Rec #:   G   ║"
  403. @ 4,0 SAY "║  Field:  -  -  ║ Page:  PgUp  PgDn  ║ Field:     ^Y    ║ Edit Field:   E   ║"
  404. @ 5,0 SAY "║  Pan:   ^- ^-  ║ File: ^PgUp ^PgDn  ║ Record:    ^U    ║ Quit/Exit:   ESC  ║"
  405. @ 6,0 SAY "╚══════════════════╩════════════════════╩══════════════════╩═══════════════════╝"
  406. RETURN              
  407.  
  408. PROCEDURE B_DrHead
  409.    * Draws the table header of fieldnames
  410.    PRIVATE temp, cur_posit, fldlen, namelen
  411.    temp = 1
  412.    @ 7,0 CLEAR
  413.    FOR cur_posit = frst_posit TO last_posit
  414.       in_val = FIELDNAME(cur_posit)
  415.       fldlen = Field_Length[cur_posit]
  416.       namelen = LEN(in_val)
  417.       @ 7,temp SAY TRIM(in_val) + REPLICATE("-",fldlen-namelen)
  418.       @ 8,temp SAY REPLICATE("═",fldlen)
  419.       temp = temp + fldlen +1
  420.    NEXT
  421.    RETURN
  422.  
  423. PROCEDURE B_ReDraw
  424.    * Draws the table of fields down and across the screen
  425.    PRIVATE down, across, cur_posit
  426.    @ 9,0 CLEAR
  427.    FOR down = 9 TO 20
  428.       last_row = down
  429.       curr_bot = RECNO()
  430.       IF DELETED()
  431.          @ down,0 SAY "*"
  432.       ENDIF
  433.       across = 1
  434.       FOR cur_posit = frst_posit TO last_posit
  435.          in_val = FIELDNAME(cur_posit)
  436.          IF TYPE(in_val) = "M"
  437.             @ down,across SAY "memo"
  438.          ELSE
  439.             @ down,across SAY &in_val
  440.          ENDIF
  441.          across = across + Field_Length[cur_posit] + 1 
  442.       NEXT
  443.       SKIP + 1
  444.       IF EOF()
  445.          down = 21
  446.          SKIP - 1
  447.       ENDIF
  448.    NEXT
  449.    RETURN
  450.  
  451. PROCEDURE B_UpRec
  452.    * B_UpRec goes up a record *
  453.    IF row_pos < 9
  454.       SKIP - 1
  455.       curr_top = RECNO()
  456.       DO B_ReDraw
  457.       GoTo curr_rec
  458.       row_pos = 9
  459.    ELSE
  460.       IF TYPE(in_val) = "M"
  461.          @ row_pos+1,col_pos SAY "memo"
  462.       ELSE
  463.          @ row_pos+1,col_pos SAY &in_val
  464.       ENDIF
  465.    ENDIF
  466.    RETURN
  467.  
  468. PROCEDURE B_DnRec
  469.    * B_DnRec getting things ready to go down *
  470.    IF row_pos > 20
  471.       SKIP
  472.       curr_top = RECNO()
  473.       DO B_ReDraw
  474.       GoTo curr_rec
  475.       row_pos = 9
  476.    ELSE
  477.       IF TYPE(in_val) = "M"
  478.          @ row_pos-1,col_pos SAY "memo"
  479.       ELSE
  480.          @ row_pos-1,col_pos SAY &in_val
  481.       ENDIF
  482.    ENDIF
  483.    RETURN
  484.  
  485. PROCEDURE B_RecNum
  486.    * B_RecNum displays the current reccord number to the screen *
  487.    @ 0,12 SAY SPACE(8)
  488.    @ 0,12 SAY curr_rec PICT "@B"
  489.    IF DELETED()
  490.      @ 00,50 SAY "*DEL*"
  491.    ELSE
  492.      @ 00,50 SAY "     "
  493.    ENDIF
  494.    RETURN
  495.  
  496. PROCEDURE B_ShoRev
  497.    PRIVATE tempit
  498.    * B_ShoRev will Reverse video the field...of current position    *
  499.    * displays accordingly to the screen at row_pos and col_pos  *
  500.    in_val = FIELDNAME(cur_field)
  501.    IF TYPE(in_val) = "M"
  502.       tempit = "memo"
  503.       @ row_pos,col_pos GET tempit
  504.    ELSE
  505.       @ row_pos,col_pos GET &in_val
  506.    ENDIF
  507.    CLEAR GETS
  508.    RETURN
  509.  
  510. PROCEDURE B_SayLt
  511.    * B_SayLT will SAY field and increment col_pos to the left *
  512.    IF TYPE(in_val) = "M"
  513.       @ row_pos,col_pos SAY "memo"
  514.    ELSE
  515.       @ row_pos,col_pos SAY &in_val
  516.    ENDIF
  517.    col_pos = col_pos - Field_Length[cur_field] - 1
  518.    RETURN
  519.  
  520. PROCEDURE B_SayRt
  521.    * B_SayRT will SAY a field and increment col_pos to the right *
  522.    IF TYPE(in_val) = "M"
  523.       @ row_pos,col_pos SAY "memo"
  524.    ELSE
  525.       @ row_pos,col_pos SAY &in_val
  526.    ENDIF
  527.    col_pos = col_pos + Field_Length[cur_field] + 1
  528.    RETURN
  529.  
  530. FUNCTION B_R_PAN
  531.    * Returns the number of the field from current first field position
  532.    * that will fit onto the screen going up in count
  533.    PRIVATE length, cnt_pos, rover
  534.    length = 0
  535.    FOR cnt_pos = cur_field TO last_fld 
  536.       rover = cnt_pos
  537.       length = length + Field_Length[cnt_pos] + 1
  538.       IF length > 80
  539.          IF rover = cur_field
  540.             RETURN(rover)
  541.          ELSE
  542.             RETURN(rover - 1)
  543.          ENDIF
  544.       ENDIF
  545.    NEXT
  546.    * The remaining fields all fit on the screen
  547.    RETURN(rover)
  548.  
  549. FUNCTION B_L_PAN
  550.    * Returns the number of the field from current last field position
  551.    * that will fit onto the screen going down in count
  552.    PRIVATE length, cnt_pos, lover
  553.    length = 0
  554.    FOR cnt_pos = cur_field TO 1 STEP -1
  555.       lover = cnt_pos
  556.       length = length + Field_Length[cnt_pos] + 1
  557.       IF length > 80
  558.          IF lover = cur_field
  559.             RETURN(lover)
  560.          ELSE
  561.             RETURN(lover + 1)
  562.          ENDIF
  563.       ENDIF
  564.    NEXT
  565.    * The remaining fields all fit on the screen
  566.    RETURN(lover)
  567.  
  568.  
  569. FUNCTION B_FLDCNT
  570.    * This function determines the number of the last field in database
  571.    PRIVATE count
  572.    count = 1
  573.    DO WHILE (count < 1025) .AND. (LEN(FIELDNAME(count+1)) > 0)
  574.       count = count + 1
  575.    ENDDO
  576.    RETURN(count)
  577.  
  578. FUNCTION B_FLDLEN
  579.    * B_FLDLEN function                     *
  580.    * Returns LEN() for character strings *
  581.    * Returns LEN(STR()) for numeric         *
  582.    * Returns 1 for logical                 *
  583.    * Returns 8 for date                     *
  584.    * Returns 4 for memo                     *
  585.    * OR Returns length of field name *
  586.    ***************************************
  587.    PARAMETER field_num
  588.    PRIVATE lenght
  589.    field_name = FIELDNAME(field_num)
  590.    DO CASE
  591.      CASE TYPE(field_name) = "C"
  592.        length = LEN(&field_name)
  593.      CASE TYPE(field_name) = "N"
  594.         length = LEN(STR(&field_name))
  595.      OTHERWISE
  596.         length = AT(TYPE(field_name), "L  M   D")
  597.    ENDCASE
  598.    IF LEN(field_name) > length
  599.      RETURN(LEN(field_name))
  600.    ELSE
  601.      RETURN(length)
  602.    ENDIF
  603.  
  604.  **[eof]
  605.